var rootview = ui("$");
var app = sm("do_App");
var page = sm("do_Page");
var nf = sm("do_Notification");
var openHelper = require("helper/open");
var bizzType = require("helper/bizzType");
var userUtil = require("helper/user");
var http = require("helper/http");
var pubUrl = require("url/pub");
var btnALayout = ui("btnALayout");
var sendALayout = ui("sendALayout");
var sendBtn = ui("sendBtn");
var cancelBtn = ui("cancelBtn");
var textContent = ui("textContent");
var httpSilence = require("helper/httpSilence");
var communityUtil = require("helper/community");

var isConcern = 2;//是否关注 1-是，2-否
var isPraised = 2;//是否关注 1-是，2-否
var bizzId;
var bizzType;
var beCommentedId = null; //被回复的评论ID
var beCommentedName = null;//被回复的用户名
var shareTitle="",shareContent="",shareImage="",shareId,shareType;
//输入框--得到焦点
/*textContent.on("focusIn", function(data, e) {
	page.fire("focusIn");
})*/
//文字改变
textContent.on("textChanged", function(data, e) {

});

//发送文字消息
sendBtn.on("touch","",3000, function(data, e) { 
	page.hideKeyboard();
	
	if(textContent.length==0){
		nf.toast("请输入内容!");
		return;
	}
	var addParams = {
            bizzId:bizzId,
            bizzType:bizzType,
			content:textContent.text,
			beCommentedId:beCommentedId,
			communityId:communityUtil.communityVisitId()
		};
	http.post(pubUrl.url.comment.doAdd,addParams,function(data){
		page.fire("sendTextMsg", textContent.text);
		textContent.text = "";
	});
	
	textContent.text = "";
	btnALayout.visible=true;
	sendALayout.visible=false;
});

//取消发送
cancelBtn.on("touch", function(data, e) { 
	textContent.setFocus(false);
	page.hideKeyboard();
	textContent.text = "";
	beCommentedId = null;
	beCommentedName = null;
	textContent.hint = "评论";
	btnALayout.visible=true;
	sendALayout.visible=false;
});

//点击评论按钮
ui("do_ALayout_6").on("touch", function(data, e) {
	btnALayout.visible=false;
	sendALayout.visible=true;
	textContent.setFocus(true);
});
//初始化
page.on("initPraise",function(data) {
	isPraised = data.isPraised;
	bizzId = data.bizzId;
	bizzType = data.bizzType;
	shareTitle=data.shareTitle;
	shareContent=data.shareContent;
	if(null!=data.shareImage){
		shareImage=data.shareImage;
	}
	shareType=data.shareType;
	shareId=data.shareId;
	if(data.isPraised==1){
		//点亮点赞按钮
		ui("do_ImageView_3").source = "source://image/common/praise1.png";
	}	
});

//点赞按钮
ui("do_ALayout_8").on("touch", function(data, e) {
	
	var addParams = {
            bizzId:bizzId,
            bizzType:bizzType,
            communityId:communityUtil.communityVisitId()
		};
	if(isPraised == 1){
		//如果已关注，再次点击则取消关注
		http.post(pubUrl.url.praise.doCancle,addParams,function(data){
			ui("do_ImageView_3").source = "source://image/common/praise.png";
			isPraised = 2;
			page.fire("onPraiseBack", data.praiseUserList);
		});
	}else{
		http.post(pubUrl.url.praise.doAdd,addParams,function(data){
			ui("do_ImageView_3").source = "source://image/common/praise1.png";
			isPraised = 1;
			page.fire("onPraiseBack", data.praiseUserList);
		});
	}	
});

//回复非当前用户时，触发显示评论输入框
page.on("commentOther",function(data) {
	if(data.beCommentedId){
		beCommentedId = data.beCommentedId;
		beCommentedName = data.beCommentedName;
		textContent.hint = "回复"+beCommentedName;
	}
	btnALayout.visible=!data.showSendText;
	sendALayout.visible=data.showSendText;
	textContent.setFocus(true);
});
ui("do_ALayout_4").on("touch", "", 300, function() {
	page.fire("onShare",{showView:"true",shareTitle:shareTitle,shareContent:shareContent,shareId:shareId,shareType:shareType,shareImage:shareImage});
});

